#
# CPL Assignment 2
# Tim Caljé, Jeroen De Raedt & Jorick Van Aken
#
class AirportsInterpreter
    
  def initialize(connectionDao)
    @connectionDao = connectionDao
    @airports = false
    @airlines = false 
    @destination = false
    @airportcode=''
    @connectinAirports = false
    @flightNr = ''
    @flydays = false
  end
  
  def airports()
    @airports = true;
    self
  end
  
  def airlines()
    @airlines = true
    self
  end
  
  def destinations(code)
    if code.length ==3 then
      @destination = true
      @airportcode = code
    else
      raise Exception, "Airport code should have 3 chars."; 
    end
    self
  end
  
  def connectingAirports(flightNr)
    if flightNr.length ==6 then
      @connectinAirports = true
      @flightNr = flightNr
    else
      raise Exception, "FlightNr code should have 6 chars."; 
    end
    self
  end
  
  def flydays(flightNr)
    if flightNr.length ==6 then
      @flydays = true
      @flightNr = flightNr
    else
      raise Exception, "FlightNr code should have 6 chars.";
    end
    self
  end
  
  def query()
    results =  Array.new
    if @airports then
      results.push('Airports:')
      results.push(@connectionDao.getAirports())
      results.push('')
    end
    if @airlines then
      results.push('Airlines:')
      results.push(@connectionDao.getAirlines())
      results.push('')
    end
    if @destination then
      results.push('Destinations:')
      results.push(@connectionDao.getDestinations(@airportcode))
      results.push('')
    end
    if @connectinAirports then
      results.push('Connected Airports for ' + @flightNr + ':')
      results.push(@connectionDao.getConnectedAirports(@flightNr))
      results.push('')
    end
    if @flydays then
      results.push('Flydays for ' + @flightNr + ':')
      results.push(@connectionDao.getFlyDays(@flightNr))
      results.push('')
    end
    results
  end
end